home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / GSys.lha / gsys / gsystem / GError.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-18  |  1.7 KB  |  113 lines

  1.  
  2. /* Author Anders Kjeldsen */
  3.  
  4. #ifndef GERROR_CPP
  5. #define GERROR_CPP
  6.  
  7. #include "gsystem/GError.h"
  8. //#include "gsystem/GObject.cpp"
  9.  
  10. GError::GError(GSTRPTR id, GSTRPTR errormsg)
  11. {
  12.     memset((void *)this, 0, sizeof (GError) );
  13.     ID = NULL;
  14.     Msg = NULL;
  15.  
  16.     if ( id && errormsg )
  17.     {
  18.         ID = new char[ strlen(id) + 1 ];
  19.         Msg = new char[ strlen(errormsg) + 1 ];
  20.         if ( ID && Msg )
  21.         {
  22.             strcpy(ID, id);
  23.             strcpy(Msg, errormsg);
  24.         }
  25.     }
  26. }
  27.  
  28. GError::~GError()
  29. {
  30.     if ( ID ) delete ID;
  31.     if ( Msg ) delete Msg;
  32.     if ( NextError ) delete NextError;
  33. }
  34.  
  35. BOOL GError::ChangeMsg(GSTRPTR errormsg)
  36. {
  37.     if ( errormsg )
  38.     {
  39.         if ( Msg )
  40.         {
  41.             if ( strlen(errormsg) > strlen(Msg) )
  42.             {
  43.                 delete Msg;
  44.                 Msg = new char[ strlen(errormsg) + 1 ];
  45.             }
  46.             strcpy(Msg, errormsg);
  47.             return TRUE;
  48.         }
  49.         else
  50.         {
  51.             Msg = new char[ strlen(errormsg) + 1 ];
  52.             if (Msg)
  53.             {
  54.                 strcpy(Msg, errormsg);
  55.                 return TRUE;
  56.             }
  57.             else return FALSE;
  58.         }
  59.     }
  60. }
  61.  
  62. void GError::PrintError()
  63. {
  64.     if ( ID && Msg)
  65.     {
  66.         printf("Error (id: %s): %s\n", ID, Msg);
  67.     }
  68. }
  69.  
  70. void GError::PrintErrors()
  71. {
  72.     printf("printing error:\n");
  73.     if ( ID && Msg)
  74.     {
  75.         printf("Error (id: %s): %s\n", ID, Msg);
  76.         if ( NextError ) NextError->PrintErrors();
  77.     }
  78. }
  79.  
  80. BOOL GError::AttachError(GError *next)
  81. {
  82.     if (!next->PrevError)
  83.     {
  84.         if ( NextError )
  85.         {
  86.             next->NextError = NextError;
  87.             NextError->PrevError = next;
  88.             next->PrevError = this;
  89.             NextError = next;
  90.         }
  91.         else
  92.         {
  93.             NextError = next;
  94.             next->PrevError = this;
  95.         }
  96.         return TRUE;
  97.     }
  98.     return FALSE;    // Error already in middle of excisting list
  99. }
  100.  
  101. BOOL GError::DetachError()
  102. {
  103.     if (PrevError)
  104.     {
  105.         NextError->PrevError = PrevError;
  106.         PrevError->NextError = NextError;
  107.         return TRUE;
  108.  
  109.     }
  110.     return FALSE;    // cannot remove first entry in list
  111. }
  112.  
  113. #endif /* GERROR_CPP */